package com.bidevalution.business.impl;

import com.bidevalution.business.context.StepType;
import com.bidevalution.business.enums.StepReviewResultType;
import com.bidevalution.business.function.FunctionCalculator;
import com.bidevalution.business.service.BeSectionExpertProgressService;
import com.bidevalution.business.service.BeSectionStepJobService;
import com.bidevalution.business.service.BeSectionStepService;
import com.bidevalution.business.vo.StepReviewVo;
import com.bidevalution.dao.entity.*;
import com.bidevalution.dao.mapper.*;
import com.bidevalution.service.layout.LayoutCode;
import com.bidevalution.support.context.Constants;
import com.bidevalution.support.context.EvalutionMethodEnum;
import com.bidevalution.support.exception.BizException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.qtp.common.data.RedisAccess;
import com.qtp.core.redis.RedisUtil;
import com.qtp.core.util.GsonUtil;
import com.qtp.core.util.IdsUtil;

import com.qtp.core.util.OConvertUtils;
import lombok.experimental.PackagePrivate;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;

/**
 * Created by glodon on 2019-08-19.
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BeSectionStepServiceImpl implements BeSectionStepService {

	@Autowired
	private BeSectionStepMapper beSectionStepMapper;
	@Autowired
	private BeMethodLayoutMapper beMethodLayoutMapper;
	@Autowired
	private BeMethodColumnMapper beMethodColumnMapper;
	@Autowired
	private BeLayoutConfigMapper beLayoutConfigMapper;
	@Autowired
	private BeMethodStepMapper beMethodStepMapper;
	@Autowired
	private BeSectionLayoutMapper beSectionLayoutMapper;
	@Autowired
	private BeMethodStepJobMapper beMethodStepJobMapper;
	@Autowired
	private BeSectionStepJobMapper beSectionStepJobMapper;
	@Autowired
	private BeMethodHeaderMapper beMethodHeaderMapper;
	@Autowired
	private BeSectionColumnMapper beSectionColumnMapper;
	@Autowired
	private BeSectionButtonMapper beSectionButtonMapper;
	@Autowired
	private BeEvalutionColumnMapper beEvalutionColumnMapper;
	@Autowired
	private BeSectionReportMapper beSectionReportMapper;
	@Autowired
	private BeMethodReportMapper beMethodReportMapper;
	@Autowired
	private BeEvalutionOutcomeMapper beEvalutionOutcomeMapper;
	@Autowired
	private BeEvalutionSummaryMapper beEvalutionSummaryMapper;
	@Autowired
	private BeSectionExpertProgressService beSectionExpertProgressService;
	@Autowired
	private BeExpertVoteResultMapper beExpertVoteResultMapper;
	@Autowired
	private BeSectionParameterMapper beSectionParameterMapper;
	@Autowired
	private BeSectionStepJobService beSectionStepJobService;
	@Autowired
	private BeSectionExpertProgressMapper beSectionExpertProgressMapper;
	@Autowired
	private BeSectionExpertInfoMapper beSectionExpertInfoMapper;

	@Autowired
	private BeSectionInfoMapper beSectionInfoMapper;

	@Autowired
	private BeSectionMethodMapper beSectionMethodMapper;
	private Logger log = Logger.getLogger(getClass());

	/**
	 * 根据标段id获取标段环节列表
	 * 
	 * @param sectionId
	 * @return
	 */
	@Override
	public List<BeSectionStep> getBeSectionStepList(String sectionId) {
		return beSectionStepMapper.getBeSectionStepList(sectionId);
	}

	/**
	 * 根据当前环节id获取子环节列表
	 * 
	 * @param parentId
	 * @return
	 */
	@Override
	public List<BeSectionStep> getChildSectionStepList(String sectionId, String parentCode){
		return beSectionStepMapper.getChildSectionStepList(sectionId, parentCode);
	}

	/**
	 * 根据当前环节id获取子环节列表
	 * 
	 * @param seqId
	 * @return
	 */
	@Override
	public BeSectionStep getSectionStepBySeqId(String seqId){
		return beSectionStepMapper.selectByPrimaryKey(seqId);
	}

	@Override
	public List<Map<String, Object>> getBeSectionStepReappraisalList(String sectionId){
		List<Map<String, Object>> dataList = beSectionStepMapper.getBeSectionStepReappraisalList(sectionId);
		List<Map<String, Object>> returnList = new ArrayList<>();
		// 循环将第一个未评审状态的环节设置为评审中
		boolean flag = true;
		for (Map<String, Object> dataMap : dataList) {
			// 前端需要，增加这个返回值
			dataMap.put("clicked", false);
			if ("未评审".equals(dataMap.get("state")) && flag) {
				dataMap.replace("state", "评审中");
				flag = false;
			}
			//查询子环节(不包含智能评审项)
			String paentCode = OConvertUtils.getString(dataMap.get("stepCode"));
			List<BeSectionStep> childSectionSteps = beSectionStepMapper.queryChildSectionSteps(sectionId,paentCode);
			if(childSectionSteps != null && !childSectionSteps.isEmpty()){
				boolean _flag = true;
				for(BeSectionStep beSectionStep : childSectionSteps){
					Map<String, Object> map = Maps.newHashMap();
                    String state = "未评审";
					map.put("clicked", false);
					map.put("sectionStepId",beSectionStep.getSeqId());
					map.put("orderNum",beSectionStep.getOrderNum());
					map.put("stepName",beSectionStep.getStepName());
					map.put("stepCode",beSectionStep.getStepCode());
					if (_flag && !"未评审".equals(dataMap.get("state")) &&
							beSectionExpertProgressMapper.selectFinishList(beSectionStep.getSeqId()).size() == beSectionExpertInfoMapper.getList(sectionId,"0").size()) {
						state = "评审结束";
					}else if(_flag && !"未评审".equals(dataMap.get("state"))){
						state = "评审中";
						_flag = false;
					}
					map.put("state",state);
					returnList.add(map);
				}
			} else{
				returnList.add(dataMap);
			}
		}
		return returnList;
	}

	@Override
	public BeSectionStep getSectionStepByCode(String sectionId, String stepCode){
		// TODO Auto-generated method stub
		return beSectionStepMapper.getSectionStepByCode(sectionId, stepCode);
	}

	@Override
	@Transactional
	public void addList(BeSectionMethod beSectionMethod, List<BeMethodStep> beMethodStepList) throws Exception {
		BeSectionStep beSectionStep = null;
		BeMethodColumn beMethodColumn = null;
		BeSectionLayout beSectionLayout = null;
		Map<String, Object> configMap = null;
		BeSectionStepJob beSectionStepJob;
		BeSectionColumn beSectionColumn;
		BeMethodStep parentMethodStep;
		BeSectionButton beSectionButton;
		BeLayoutConfig beLayoutConfig;
		List<BeMethodHeader> beMethodHeaders;
		BeSectionReport beSectionReport;
		String sectionId = beSectionMethod.getSectionId();
		for (BeSectionStep sectionStep : beSectionStepMapper.getBeSectionStepList(sectionId)) {
			beSectionColumnMapper.deleteByStepId(sectionStep.getSeqId());
			beSectionButtonMapper.deleteByStepId(sectionStep.getSeqId());
		}
		beSectionStepJobMapper.deleteBySectionId(sectionId);
		beSectionLayoutMapper.deleteBySectionId(sectionId);
		beSectionReportMapper.deleteBySectionId(sectionId);
		beEvalutionOutcomeMapper.deleteBySectionId(sectionId);
		beEvalutionSummaryMapper.deleteBySectionId(sectionId);
		beSectionStepMapper.deleteBySectionId(sectionId);
		beExpertVoteResultMapper.deleteBySectionId(sectionId);
		beSectionExpertProgressService.addProgressList(beSectionMethod.getSectionId(), beSectionMethod.getSubmitCode());
		List<BeSectionStep> beSectionStepList = new ArrayList<BeSectionStep>();
		List<String> editColumnList = new ArrayList<String>();
		// 环节任务复制
		for (BeMethodReport beMethodReport : beMethodReportMapper.selectList(beSectionMethod.getMethodId())) {
			beSectionReport = new BeSectionReport();
			beSectionReport.setReportExpert(beMethodReport.getReportExpert());
			beSectionReport.setReportName(beMethodReport.getReportName());
			beSectionReport.setReportPath(beMethodReport.getReportPath());
			beSectionReport.setSectionId(sectionId);
			beSectionReport.setSectionStepCode(beMethodReport.getSectionStepCode());
			beSectionReport.setSeqId(IdsUtil.uuid());
			beSectionReport.setReportSort(beMethodReport.getReportSort());
			beSectionReportMapper.insert(beSectionReport);
		}
		// 获取可编辑字段
		for (BeEvalutionColumn beEvalutionColumn : beEvalutionColumnMapper.selectList()) {
			editColumnList.add(beEvalutionColumn.getColumnCode());
		}
		Map<String, Object> sectionParameterMap = Maps.newHashMap();
		for (BeSectionParameter beSectionParameter : beSectionParameterMapper.selectList(sectionId)) {
			sectionParameterMap.put("$PARAM_" + beSectionParameter.getParamId(), beSectionParameter.getParamValue());
		}
		String formulaConfig = "";
		// 循环方法环节数据
		for (BeMethodStep beMethodStep : beMethodStepList) {
			//商务标=1  技术标=2  资信标=4  如果$PARAM_Module小于4，说明资信标没有勾选，不同步资信标环节信息
			//此条件只针对于施工综合预审、监理综合、设计预审、工程总承包预审
			if(Constants.IS_HIDDEN_CREDIT_METHOD_CODE.contains(beSectionMethod.getMethodCode())
					&& OConvertUtils.getInt(sectionParameterMap.get("$PARAM_Module")) < Constants.FOUR
					&& StepType.Credit.getCode().equals(beMethodStep.getStepType())){
				System.out.println("*******************************"+beMethodStep.getStepName());
				continue;
			}
			//企业资质有业绩同步有业绩的环节，否则同步没有业绩的企业资质环节
			if (("1".equals(OConvertUtils.getString(sectionParameterMap.get("$PARAM_ProjPerf"), "0"))
					&& StepType.NotProjPerf.getCode().equals(beMethodStep.getStepType()))
					|| ("0".equals(OConvertUtils.getString(sectionParameterMap.get("$PARAM_ProjPerf"), "0"))
					&& StepType.ProjPerf.getCode().equals(beMethodStep.getStepType()))) {
				System.out.println("*******************************" + beMethodStep.getStepName());
				continue;
			}
			log.info("环节同步>>>>>>>>>>");
			// 新增标段环节
			formulaConfig = beMethodStep.getFormulaConfig();
			if (!StringUtils.isEmpty(formulaConfig)) {
				try {
					// 公式计算结果
					if (formulaConfig.toLowerCase().startsWith("{mel[")) {
						formulaConfig = formulaConfig.substring(5, formulaConfig.length() - 2);
						FunctionCalculator.computeMVEL(formulaConfig, sectionParameterMap);
					} else if (formulaConfig.toLowerCase().startsWith("{ael[")) {
						formulaConfig = formulaConfig.substring(5, formulaConfig.length() - 2);
						FunctionCalculator.computeAviator(formulaConfig, sectionParameterMap);
					}
					log.info("参数定义:" + sectionParameterMap);
					if (!"1".equals(sectionParameterMap.get("isDisplay"))) {
						continue;
					}
				} catch (Exception e) {
					log.error(e.getMessage(), e);
				}

			}
			beSectionStep = new BeSectionStep();
			beSectionStep.setSeqId(IdsUtil.uuid().replaceAll("-", ""));
			beSectionStep.setCreateTime(new Date());
			beSectionStep.setLoadFunction(beMethodStep.getLoadFunction());
			beSectionStep.setOrderNum(beMethodStep.getOrderNum());
			beSectionStep.setStepType(beMethodStep.getStepType());
			beSectionStep.setFormulaConfig(beMethodStep.getFormulaConfig());
			if ("0".equals(beMethodStep.getParentId())) {
				parentMethodStep = beMethodStepMapper.selectByPrimaryKey(beMethodStep.getParentId());
				beSectionStep.setParentCode("0");
			} else {
				parentMethodStep = beMethodStepMapper.selectByPrimaryKey(beMethodStep.getParentId());
				// 当前这个环节为废数据
				if (parentMethodStep == null) {
					continue;
				}
				beSectionStep.setParentCode(parentMethodStep.getStepCode());
			}

			beMethodColumn = beMethodColumnMapper.selectByPrimaryKey(beMethodStep.getRelatedColumnId());
			if (beMethodColumn != null) {
				beSectionStep.setRelatedColumnCode(beMethodColumn.getColumnCode());
				beSectionStep.setRelatedLayoutCode(beMethodColumn.getLayoutCode());
				beSectionStep.setRelatedStepCode(
						beMethodStepMapper.selectByPrimaryKey(beMethodColumn.getMethodStepId()).getStepCode());
			}
			beSectionStep.setSectionId(sectionId);
			beSectionStep.setStepCode(beMethodStep.getStepCode());
			beSectionStep.setStepName(beMethodStep.getStepName());
			// stepCode 1 和2默认分配给专家承诺和领导选举
			if ("1".equals(beSectionStep.getStepCode())) {
				beSectionStep.setStepUrl("expert_commitment");
			} else if ("2".equals(beSectionStep.getStepCode())) {
				beSectionStep.setStepUrl("selection_leader");
			} else {
				beLayoutConfig = beLayoutConfigMapper.selectByPrimaryKey(beMethodStep.getLayoutConfigId());
				beSectionStep.setStepUrl(beLayoutConfig == null ? "" : beLayoutConfig.getTemplateUrl());
			}
			beSectionStep.setUpdateTime(new Date());
			beSectionStepMapper.insert(beSectionStep);
			beSectionStepList.add(beSectionStep);
			log.info("按钮同步>>>>>>>>>>");
			// 添加页面按钮区域数据
			beMethodHeaders = beMethodHeaderMapper.selectForList(beMethodStep.getSeqId());

			for (BeMethodHeader beMethodHeader : beMethodHeaders) {
				beSectionButton = new BeSectionButton();
				beSectionButton.setClickFunction(beMethodHeader.getClickFunction());
				beSectionButton.setControlCode(beMethodHeader.getControlCode());
				beSectionButton.setControlType(beMethodHeader.getControlType());
				beSectionButton.setControlValue(beMethodHeader.getControlValue());
				beSectionButton.setCreateTime(new Date());
				beSectionButton.setDisabledTip("");
				beSectionButton.setOrderNum(beMethodHeader.getOrderNum());
				beSectionButton.setIsDisabled("0");
				beSectionButton.setLayoutCode(LayoutCode.Header.name());
				beSectionButton.setSectionStepId(beSectionStep.getSeqId());
				beSectionButton.setPermissionConfig(beMethodHeader.getPermissionConfig());
				beSectionButton.setUpdateTime(new Date());
				beSectionButton.setWidth(StringUtils.isEmpty(beMethodHeader.getControlWidth()) ? 80
						: Integer.valueOf(beMethodHeader.getControlWidth()));
				beSectionButtonMapper.insert(beSectionButton);
			}

			// 添加布局配置数据
			if (beMethodHeaders.size() > 0) {
				beSectionLayout = new BeSectionLayout();
				beSectionLayout.setLayoutCode(LayoutCode.Header.name());
				beSectionLayout.setConfig(GsonUtil.toJson(configMap));
				beSectionLayout.setCreateTime(new Date());
				beSectionLayout.setUpdateTime(new Date());
				beSectionLayout.setLayoutText("");
				beSectionLayout.setSectionStepId(beSectionStep.getSeqId());
				beSectionLayoutMapper.insert(beSectionLayout);
			}
			log.info("页面布局同步>>>>>>>>>>");
			// 添加页面表格区域配置
			for (BeMethodLayout beMethodLayout : beMethodLayoutMapper.selectList(beMethodStep.getSeqId())) {
				beSectionLayout = new BeSectionLayout();
				beSectionLayout.setLayoutCode(beMethodLayout.getLayoutCode());
				beSectionLayout.setConfig(beMethodLayout.getSqlConfig());
				beSectionLayout.setCreateTime(new Date());
				beSectionLayout.setUpdateTime(new Date());
				beSectionLayout.setLayoutText(beMethodLayout.getLayoutText());
				beSectionLayout.setClickFunction(beMethodLayout.getClickFunction());
				beSectionLayout.setSectionStepId(beSectionStep.getSeqId());
				beSectionLayout.setDisplayOrder(beMethodLayout.getDisplayOrder());
				beSectionLayout.setCascadeLayoutCode(beMethodLayout.getCascadeLayoutCode());
				beSectionLayoutMapper.insert(beSectionLayout);
				log.info(beSectionLayout.getLayoutCode() + ":布局字段同步>>>>>>>>>>");
				for (BeMethodColumn _beMethodColumn : beMethodColumnMapper.selectListByStepId(beMethodStep.getSeqId(),
						beMethodLayout.getLayoutCode())) {
					beSectionColumn = new BeSectionColumn();
					beSectionColumn.setClickFunction(_beMethodColumn.getClickFunction());
					beSectionColumn.setColumnCode(_beMethodColumn.getColumnCode());
					beSectionColumn.setColumnDescription(_beMethodColumn.getColumnDescription());
					beSectionColumn.setColumnText(_beMethodColumn.getColumnText());
					beSectionColumn.setColumnWidth(_beMethodColumn.getColumnWidth());
					beSectionColumn.setCreateTime(new Date());
					beSectionColumn.setInputType(_beMethodColumn.getInputType());
					beSectionColumn.setOrderNum(_beMethodColumn.getOrderNum());
					beSectionColumn.setDefaultValue(_beMethodColumn.getDefaultValue());
					beSectionColumn.setFormulaConfig(_beMethodColumn.getFormulaConfig());
					beSectionColumn.setPermissionConfig(_beMethodColumn.getPermissionConfig());
					beSectionColumn.setLayoutCode(beMethodLayout.getLayoutCode());
					beSectionColumn.setValidator(_beMethodColumn.getValidator());
					beSectionColumn.setSectionStepId(beSectionStep.getSeqId());
					beSectionColumn.setUpdateTime(new Date());
					// 判断是否编辑字段
					if (editColumnList.contains(_beMethodColumn.getColumnCode())) {
						beSectionColumn.setEnableEdit("1");
					} else {
						beSectionColumn.setEnableEdit("0");
					}
					beSectionColumn.setRestrictTip(_beMethodColumn.getRestrictTip());
					beSectionColumn.setColumnConfig(_beMethodColumn.getColumnConfig());
					beSectionColumnMapper.insert(beSectionColumn);
				}
			}
			// 环节任务复制
			for (BeMethodStepJob beMethodStepJob : beMethodStepJobMapper.selectListByStepId(beMethodStep.getSeqId())) {
				beSectionStepJob = new BeSectionStepJob();
				beSectionStepJob.setCreateTime(new Date());
				beSectionStepJob.setIsFinish("0");
				beSectionStepJob.setJobClass(beMethodStepJob.getJobClass());
				beSectionStepJob.setJobContent(beMethodStepJob.getJobContent());
				beSectionStepJob.setJobName(beMethodStepJob.getJobName());
				beSectionStepJob.setSeqId(IdsUtil.uuid().replaceAll("-", ""));
				beSectionStepJob.setSectionStepId(beSectionStep.getSeqId());
				beSectionStepJob.setStage(beMethodStepJob.getStage());
				beSectionStepJob.setUpdateTime(beSectionStep.getUpdateTime());
				beSectionStepJob.setOrderNum(beMethodStepJob.getOrderNum());
				beSectionStepJob.setJobState(beMethodStepJob.getJobState());
				beSectionStepJob.setIsAdvanceExecute(beMethodStepJob.getIsAdvanceExecute());
				beSectionStepJob.setSectionId(beSectionStep.getSectionId());
				beSectionStepJob.setUnionChildren(beMethodStepJob.getUnionChildren());
				beSectionStepJob.setLayoutCode(beMethodStepJob.getLayoutCode());
				beSectionStepJob.setJobCount(1);
				beSectionStepJob.setIsBusinessBefore(beMethodStepJob.getIsBusinessBefore());
				beSectionStepJob.setCheckJobClass(beMethodStepJob.getCheckJobClass());
				beSectionStepJob.setCheckMsgType(beMethodStepJob.getCheckMsgType());
				beSectionStepJob.setCheckJobParams(beMethodStepJob.getCheckJobParams());
				beSectionStepJobMapper.insert(beSectionStepJob);
			}

		}
		// 插入绑定的环节ID
		for (BeSectionStep _beSectionStep : beSectionStepList) {
			if (!StringUtils.isEmpty(_beSectionStep.getRelatedStepCode())) {
				beSectionStep = beSectionStepMapper.getSectionStepByCode(_beSectionStep.getSectionId(),
						_beSectionStep.getRelatedStepCode());
				if (beSectionStep != null) {
					_beSectionStep.setRelatedStepId(beSectionStep.getSeqId());
					beSectionStepMapper.updateByPrimaryKey(_beSectionStep);
				}
			}
		}

	}

	@Override
	public List<BeSectionStep> getAllStepList(String sectionId) {
		return beSectionStepMapper.getAllStepList(sectionId);
	}

	@Override
	public BeSectionStep selectByPrimaryKey(String seqId) throws Exception {
		return beSectionStepMapper.selectByPrimaryKey(seqId);
	}

	@Override
	public List<BeSectionStep> getPreStepList(BeSectionStep beSectionStep) {
		return beSectionStepMapper.getPretStepList(beSectionStep.getSectionId(), beSectionStep.getParentCode(),
				beSectionStep.getOrderNum());
	}

	/**
	 * 更新当前环节为正在评审的环节
	 */
	@Override
	@Transactional
	public void updateStepActive(String sectionStepId) throws Exception {
		synchronized (this) {
			BeSectionStep beSectionStep = beSectionStepMapper.selectByPrimaryKey(sectionStepId);
			// 判断是否已经重置，并且是第一级环节
			if (beSectionStep != null && "0".equals(beSectionStep.getParentCode())
					&& !"1".equals(beSectionStep.getIsActive())) {
				// 获取前面同级别环节
				List<BeSectionStep> beSectionStepList = beSectionStepMapper.getPretStepList(
						beSectionStep.getSectionId(), beSectionStep.getParentCode(), beSectionStep.getOrderNum());
				log.info("前面环节的总数:" + beSectionStepList.size());
				if (beSectionStepList.size() > 0) {
					// 取出最后一条记录
					BeSectionStep preStep = beSectionStepList.get(beSectionStepList.size() - 1);
					log.info("上个环节:" + preStep == null ? "不存在>>>>>>>>>>>"
							: (preStep.getStepName() + ":" + preStep.getStepCode() + ">>>>>>>>>>>>>>>"));
					Boolean isFinish = beSectionExpertProgressService.getFinishStatus(preStep.getSeqId());
					log.info("上个环节完成状态:" + isFinish);
					if ("1".equals(preStep.getStepCode()) || isFinish) {
						// 环节代码,承诺书:1;当前一个环节为承诺书或者已经完成，才重置下一个环节为活动状态置为1
						
						//更新环节为正在评审中
						beSectionStepMapper.resetActive(beSectionStep.getSectionId());
						beSectionStep.setIsActive(Constants.STR_YES);
						beSectionStepMapper.updateByPrimaryKey(beSectionStep);
					}
				}
			}
		}

	}

	@Override
	public StepReviewVo review(BeSectionStep beSectionStep) throws Exception{
		StepReviewVo stepReviewVO = new StepReviewVo(StepReviewResultType.Ok);
		String sectionId = beSectionStep.getSectionId();

		List<BeSectionParameter> parameters = beSectionParameterMapper.queryListByParamIds(sectionId, new String[]{Constants.ProjPerf});

		// 有业绩要求
		if (parameters.size() > 0 && Constants.STR_YES.equals(parameters.get(0).getParamValue())) {
			BeSectionColumn beSectionColumn = new BeSectionColumn();
			beSectionColumn.setSectionStepId(beSectionStep.getSeqId());
			beSectionColumn.setColumnText("最终评审结果");
			BeSectionColumn result = beSectionColumnMapper.getBeSectionColumn(beSectionColumn);

			if (result == null) {
				throw new Exception("没有找到对应的列数据");
			}

			BeEvalutionOutcome beEvalutionOutcome = new BeEvalutionOutcome();
			beEvalutionOutcome.setSectionStepId(beSectionStep.getSeqId());
			beEvalutionOutcome.setIsDel(Constants.STR_NO);

			String name  = result.getColumnCode();
			Class clazz = beEvalutionOutcome.getClass();
			Field field = clazz.getDeclaredField(name);
			field.setAccessible(true);
			field.set(beEvalutionOutcome, Constants.STR_YES);
//			Method m = clazz.getDeclaredMethod("set", String.class);
//			m.invoke(beEvalutionOutcome, Constants.STR_YES);

			List<BeEvalutionOutcome> list = beEvalutionOutcomeMapper.findBeEvalutionOutcomes(beEvalutionOutcome);

			Set<String> enterprises = new HashSet<>();

			for (BeEvalutionOutcome item : list) {
				enterprises.add(item.getEnterpriseId());
			}

			BeSectionMethod beSectionMethod = beSectionMethodMapper.selectByPrimaryKey(sectionId);

			EvalutionMethodEnum evalutionMethodEnum = EvalutionMethodEnum.get(beSectionMethod.getMethodCode());
			int minSizw = 0;
			switch (evalutionMethodEnum) {
				// 设计综合后审、设计评定分离、工程总承包后审
				case SJZH_ZGHS:
				case SJPD:
				case GCZCBZH_ZGHS:
					minSizw = 7;
					break;
				// 施工信价量化法、施工综合后审、监理综合
				case JLZH:
				case SGXJLH:
				case SGZHF_ZGHS:
				case SGXJLH_JYJS:
					minSizw = 15;
					break;
			}
			// 确实是否有业绩
			if (enterprises.size() < minSizw) {
				String msg = String.format("通过资格审查的投标人＜ %s个，本次评标无法继续进行，请招标人重招！", minSizw);
				stepReviewVO = new StepReviewVo(StepReviewResultType.Info, msg);
			}
		}

		return stepReviewVO;
	}

	@Override
	public List<BeSectionStep> getNextStepList(BeSectionStep beSectionStep) {
		return beSectionStepMapper.getNextStepList(beSectionStep.getSectionId(),beSectionStep.getParentCode(), beSectionStep.getOrderNum());
	}

	@Override
	public List<BeSectionStep> getAllChildSectionStep(String sectionId, String parentCode) {

		return beSectionStepMapper.getAllChildSectionStep(sectionId, parentCode);
	}

}
